home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14750 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  36 lines

  1. Path: news.compuserve.com!newsmaster
  2. From: Philippe Verdy <100105.3120@compuserve.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Bletcherous kludge!
  5. Date: 1 Apr 1996 23:29:31 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4jposr$lhj@dub-news-svc-6.compuserve.com>
  8. NNTP-Posting-Host: ad15-078.compuserve.com
  9.  
  10. jlilley@ix.netcom.com (John Lilley) s'Θcrit :
  11. > In article <4jhr2b$9ou@portal.gmu.edu>, rraffer1@osf1.gmu.edu says...
  12. > >
  13. > >I am trying to get the contents of a custom String class to be converted
  14. > >into numeric data, ie float.  The String class consists of :
  15. > >
  16. > >Buffer:  a null-terminated array of char
  17. > C++ still has atof().  There is probably a more elegant, C++ correct approach 
  18. > that I don't know of.
  19. > john lilley
  20. The double atof(char*) function (from <stdlib.h>) is elegant
  21. for C++: it is perfectly defined, type-safe, and has no side
  22. effect on its arguments and in its environment. So it is
  23. a perfect conversion method which applies on a (char *) object.
  24.  
  25. We cannot say it about sscanf(string, "%lf", &doublevar)
  26. because type-safety on the third argument and later is not
  27. guaranteed, this is why iostreams where created !
  28.  
  29. Even though most of <stdlib.h> function were commonly used in
  30. C, does not mean you cannot use them safely in C++ !
  31.  
  32. Don't discriminate !
  33.